#include <stdio.h>
#include <stdlib.h>

typedef struct lineStack
{
    int elem;
    struct lineStack* next;
}lineStack;

// 入栈
lineStack* push(lineStack* st, int elem)
{
    lineStack* line = (lineStack*)malloc(sizeof(lineStack));
    if(line == NULL)
    {
        printf("入栈元素空间开辟失败...");
        return st;
    }
    line->elem = elem;
    line->next = st;
    st = line;
    return st;
}

// 出栈
lineStack* pop(lineStack* st)
{
    if(st == NULL)
    {
        printf("栈空...\n");
        return st;
    }
    else
    {
        lineStack* temp = st->next;
        printf("出栈元素：%d\n", st->elem);
        free(st);
        st = NULL;
        return temp;
    }
}

int main()
{
    // 初始化栈底元素
    lineStack* st = NULL;
    st = push(st, 2);
    st = push(st, 1);
    st = push(st, 5);
    st = push(st, 3);
    st = push(st, 4);
    st = pop(st);
    st = pop(st);
    st = pop(st);
    st = pop(st);
    st = pop(st);
    st = pop(st);
    return 0;
}